package com.example.room.mv;

import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;

import com.example.room.mv.OrderViewModel;
import com.example.room.repository.OrderRepository;

@Deprecated
public class OrderViewModelFactory implements ViewModelProvider.Factory {

    private final OrderRepository orderRepository;

    public OrderViewModelFactory(OrderRepository orderRepository) {
        this.orderRepository = orderRepository;
    }

    @Override
    public <T extends ViewModel> T create(Class<T> modelClass) {
        if (modelClass.isAssignableFrom(OrderViewModel.class)) {
            // 如果请求的 ViewModel 是 UserViewModel 类型，就返回使用 UserRepository 构造的 UserViewModel 实例
            return (T) new OrderViewModel(orderRepository);
        }
        throw new IllegalArgumentException("Unknown ViewModel class");
    }
}